import { NestFactory } from '@nestjs/core'
import { NestExpressApplication } from '@nestjs/platform-express'
import { AppModule } from './app.module'
import { HttpExceptionFilter } from './filters/http.filter'
import { HttpInterceptor } from './interceptor/http.interceptor'
import { logger, regSwagger } from './common'
import config from './config'
import { join } from 'path'

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule)
  // 接口文档
  config.swagger.enabled && regSwagger(app)
  // 全局注册错误的过滤器
  app.useGlobalFilters(new HttpExceptionFilter())
  // 全局注册拦截器
  app.useGlobalInterceptors(new HttpInterceptor())
  // 跨域
  config.server.cors && app.enableCors()
  // web服务
  console.log(join(__dirname, '..', 'public'))
  app.useStaticAssets(join(__dirname, '..', 'public'))
  await app.listen(config.server.port)
  logger.info('test log server reboot')
}

bootstrap()
